package com.activity.fragment;

import android.view.View;

import com.activity.adapter.MonthAdapter;
import com.activity.adapter.SheetAdapter;
import com.activity.shop.ClockDetailActivity;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.TimePickerView;
import com.donkingliang.groupedadapter.adapter.GroupedRecyclerViewAdapter;
import com.donkingliang.groupedadapter.holder.BaseViewHolder;
import com.example.apple.ddhr_new.activity.widget.Dialog;
import com.example.apple.ddhr_new.utils.ActivityUtil;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DefineSheetQueryFragment extends BaseListViewFragment {

    SheetAdapter sheetAdapter ;
    @Override
    public void createView() {
        super.createView();
        refreshLayout.setEnableLoadMore(false);
        sheetAdapter = new SheetAdapter(mContext);
        sheetAdapter.hasHeader=true;
        recycleView.setAdapter(sheetAdapter);

        sheetAdapter.setOnChildClickListener(new GroupedRecyclerViewAdapter.OnChildClickListener() {
            @Override
            public void onChildClick(GroupedRecyclerViewAdapter adapter, BaseViewHolder holder, int groupPosition, int childPosition) {

//                ActivityUtil.startActivity(mContext,ClockDetailActivity.class);
            }
        });
        sheetAdapter.monthListener = new MonthAdapter.MonthListener() {
            @Override
            public void beginTimeClick() {
                Calendar min = Calendar.getInstance();
                Calendar max = Calendar.getInstance();
                Calendar selectDate = Calendar.getInstance();
                min.set(1900,1,1);
                max.setTime(new Date());

                TimePickerView builder = Dialog.popTime(mContext,min,max, new OnTimeSelectListener() {
                    @Override
                    public void onTimeSelect(Date date, View v) {
                        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                        String dateString = simpleDateFormat.format(date);
                        sheetAdapter.beginTime = dateString;


                    }
                });

                // 如果不设置的话，默认是系统时间*/


                if(sheetAdapter.beginTime==null){
                    selectDate.setTime(new Date());
                }else
                {
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                    try {
                        selectDate.setTime(simpleDateFormat.parse(sheetAdapter.beginTime));
                    } catch (ParseException e) {

                    }
                }
                builder.setDate(selectDate);
                builder.show();
            }

            @Override
            public void endTimeClick() {
                Calendar min = Calendar.getInstance();
                Calendar max = Calendar.getInstance();
                Calendar selectDate = Calendar.getInstance();
                min.set(1900,1,1);
                max.setTime(new Date());

                TimePickerView builder = Dialog.popTime(mContext,min,max, new OnTimeSelectListener() {
                    @Override
                    public void onTimeSelect(Date date, View v) {
                        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                        String dateString = simpleDateFormat.format(date);
                        sheetAdapter.endTime = dateString;


                    }
                });

                // 如果不设置的话，默认是系统时间*/


                if(sheetAdapter.endTime==null){
                    selectDate.setTime(new Date());
                }else
                {
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                    try {
                        selectDate.setTime(simpleDateFormat.parse(sheetAdapter.endTime));
                    } catch (ParseException e) {

                    }
                }
                builder.setDate(selectDate);
                builder.show();
            }

            @Override
            public void queryClick() {

            }
        };



    }
}
